package com.example.glxt1.exeception;

import com.example.glxt1.common.Result;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class MyExeceptionHandler {
    /**
     * 业务异常 统一处理
     */
    @ExceptionHandler(value = ServiceException.class)
//    @ResponseStatus(HttpStatus.BAD_REQUEST)
    @ResponseBody
    public Result exceptionHandler400(ServiceException e){
        return Result.error(e.getCode(),e.getMessage());
    }
}
